package com.dietmanager.model;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class DailyLogModel implements Serializable {
	private static final long serialVersionUID = 682348763;
	private Map<String, DailyLog> logArr = new HashMap<String, DailyLog>();
	
	public boolean hasDailyLog(Date date) {
		return (logArr.get(convertDateTostring(date)) == null) ? false : true;
	}
	
	public void addDailyLog(Date date) {
		DailyLog log;
		if(!hasDailyLog(date)) {
			log = new DailyLog();
			logArr.put(convertDateTostring(date), log);
		}
	}
	
	public ArrayList<FoodModel> getFoods(Date date) {
		return logArr.get(convertDateTostring(date)).getFoodArr();
	}

	public int getWeight(Date date) {
		return logArr.get(convertDateTostring(date)).getWeight();
	}

	public int getCalorieLimit(Date date) {
		return logArr.get(convertDateTostring(date)).getCalorieLimit();
	}

	public void addFood(Date date, FoodModel food) {
		logArr.get(convertDateTostring(date)).addFood(food);
	}

	public void removeFood(Date date, FoodModel food) {
		logArr.get(convertDateTostring(date)).removeFood(food);
	}

	public void setWeight(Date date, int weight) {
		logArr.get(convertDateTostring(date)).setWeight(weight);
	}

	public void setCalorieLimit(Date date, int calorieLimit) {
		logArr.get(convertDateTostring(date)).setCalorieLimit(calorieLimit);
	}

	private String convertDateTostring(Date date) {
		SimpleDateFormat sdf = new SimpleDateFormat("dd MM yyyy");
		String dateStr = sdf.format(date);
		return dateStr;
	}
	
	private class DailyLog {
		private ArrayList<FoodModel> foodArr = new ArrayList<FoodModel>();
		private int weight;
		private int calorieLimit;
		
		public int getCalorieLimit() {
			return calorieLimit;
		}
		
		public void setCalorieLimit(int calorieLimit) {
			this.calorieLimit = calorieLimit;
		}
		
		public int getWeight() {
			return weight;
		}
		
		public void setWeight(int weight) {
			this.weight = weight;
		}
		
		public ArrayList<FoodModel> getFoodArr() {
			return foodArr;
		}
		
		public void addFood(FoodModel food) {
			this.foodArr.add(food);
		}

		public void removeFood(FoodModel food) {
			this.foodArr.remove(food);
		}
	}
}
